<template>
  <el-card class="box-card">
    <el-form :inline="true" :model="query" class="demo-form-inline">
      <el-form-item label="租客">
        <el-input v-model="query.renter" placeholder="租客"></el-input>
      </el-form-item>
      <el-form-item label="房源类型">
        <el-select v-model="query.typeId" placeholder="房源类型" clearable>
          <el-option :label="item.typeName" :value="item.id" v-for="item in types"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="起租日期">
        <el-date-picker
            v-model="query.startRent"
            type="date"
            value-format="yyyy/MM/dd"
            placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList()">查询</el-button>
        <el-button type="primary" icon="el-icon-edit" @click="to_add" circle></el-button>
      </el-form-item>
    </el-form>

    <el-table
        :data="list"
        style="width: 130%">
      <el-table-column
          label="租客名称"
          width="130">
        <template slot-scope="scope">
          <span v-html="scope.row.renter"></span>
        </template>
      </el-table-column>
      <el-table-column
          prop="number"
          label="租房合同编号"
          width="180">
      </el-table-column>
      <el-table-column
          prop="phone"
          label="电话"
          width="130">
      </el-table-column>
      <el-table-column
          prop="message"
          label="房源信息"
          width="130">
      </el-table-column>
      <el-table-column
          prop="typeName"
          label="房源类型"
          width="130">
      </el-table-column>
      <el-table-column
          prop="startRent"
          label="起租日期"
          width="130">
      </el-table-column>
      <el-table-column
          prop="endRent"
          label="结束日期"
          width="130">
      </el-table-column>
      <el-table-column
          prop="oshitsukeType"
          label="押付方式"
          width="130">
      </el-table-column>
      <el-table-column
          prop="deposit"
          label="押金"
          width="130">
      </el-table-column>
      <el-table-column
          prop="rental"
          label="租金"
          width="100">
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.pageNum"
        :page-sizes="[3, 4, 5]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>

  </el-card>
</template>

<script>
export default {
  name: "ListView",
  data() {
    return{
      list:[],
      types:[],
      query:{
        pageNum:1,
        pageSize:3,
        typeId:null,
        startRent:null,
      },
      total:null
    }
  },
  methods:{
    to_add() {
      this.$router.push('/add');
    },
    getList() {
      this.axios.get(this.$monthHost + 'renting/list',{params:this.query}).then(res=>{
       this.list = res.data.data.list;
       this.query.pageNum = res.data.data.pageNum;
       this.query.pageSize = res.data.data.pageSize;
       this.total = res.data.data.total;
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.query.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.query.pageNum = val;
      this.getList();
    },
    getType() {
      this.axios.get(this.$monthHost + 'type/getAll').then(res=>{
        this.types = res.data.data;
      });
    },
  },
  created() {
    this.getList();
    this.getType();
  }
}
</script>

<style scoped>
.box-card {
  margin-left: 5%;
  margin-right: 5%;
}
</style>